package xyz.hzxiao.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;
import xyz.hzxiao.UserAuthorityEntity;
import xyz.hzxiao.UserEntity;
import xyz.hzxiao.api.UserApi;
import xyz.hzxiao.authority.service.UserAuthorityService;
import xyz.hzxiao.user.mapper.UserMapper;

import javax.annotation.Resource;

/**
 * 用户实现类
 *
 * @author ：FuXx
 * @className : xyz.hzxiao.user.service.impl.UserServiceImpl
 * @since ：2023/5/13
 */
@DubboService
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserApi {

    @Resource
    private UserAuthorityService userAuthorityService;


    @Override
    public UserEntity findUserById(Long id) {
        UserEntity entity = this.getById(id);
        System.out.println("用户信息：" + entity);
        return entity;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveNewUser(UserEntity entity) {
        this.save(entity);
        int i = 1 / 0;
        UserAuthorityEntity authorityEntity = new UserAuthorityEntity();
        authorityEntity.setUserId(entity.getId());
        authorityEntity.setAuthorityId(12);
        userAuthorityService.save(authorityEntity);
        return true;
    }
}
